﻿package plugin.gameHall.game
{
    import __AS3__.vec.*;
    import com.adobe.serialization.json.*;
    import com.core.*;
    import com.sh.game.global.*;
    import flash.events.*;
    import flash.external.*;
    import flash.net.*;
    import morn.core.components.*;
    import plugin.gameHall.*;
    import plugin.gameHall.game.vplan.*;
    import uiresource.vplan.*;

    public class VplanCon extends VPlanUI
    {
        private var _instance:Vplan;
        private var _pages:Vector.<IVplan>;
        private var _index:int;
        private var loader:URLLoader;

        public function VplanCon(param1:Vplan)
        {
            this._instance = param1;
            return;
        }// end function

        override protected function createChildren() : void
        {
            viewClassMap["uiresource.vplan.DengJiLiBaoUI"] = DengJiLiBaoCtrl;
            viewClassMap["uiresource.vplan.HuiYuanWeiLiUI"] = HuiYuanWeiLiCtrl;
            viewClassMap["uiresource.vplan.MeiRiLiBaoUI"] = MeiRiLiBaoCtrl;
            viewClassMap["uiresource.vplan.TeGongLiBaoUI"] = TeGongLiBaoCtrl;
            viewClassMap["uiresource.vplan.TeQuanZongLuanUI"] = TeQuanZongLuanCtrl;
            loadUI("VPlan.xml");
            return;
        }// end function

        override protected function initializeView() : void
        {
            this._pages = new Vector.<IVplan>;
            this._pages.push(tegongZl, tegongLb, meiriLb, dengjiLb, huiyuanWl);
            var _loc_1:* = Control.create(VPlanControl, this);
            ModelProxy.addObserver("vplan", _loc_1);
            this.initEvent();
            this.showPage(1);
            return;
        }// end function

        private function initEvent() : void
        {
            var _loc_1:int = 1;
            while (_loc_1 <= this._pages.length)
            {
                
                (this["btn" + _loc_1] as Button).addEventListener(MouseEvent.CLICK, this.pageHandler);
                _loc_1++;
            }
            closeBtn.addEventListener(MouseEvent.CLICK, this.closeClickHandler);
            ktyueBtn.addEventListener(MouseEvent.CLICK, this.ktyueBtnClickHandler);
            ktnianBtn.addEventListener(MouseEvent.CLICK, this.ktnianBtnClickHandler);
            return;
        }// end function

        protected function ktnianBtnClickHandler(event:MouseEvent) : void
        {
            ExternalInterface.call("yearvplanmon");
            return;
        }// end function

        protected function ktyueBtnClickHandler(event:MouseEvent) : void
        {
            ExternalInterface.call("monthvplanmon");
            return;
        }// end function

        protected function closeClickHandler(event:MouseEvent) : void
        {
            this.close();
            return;
        }// end function

        protected function pageHandler(event:MouseEvent) : void
        {
            var _loc_2:int = 1;
            while (_loc_2 <= this._pages.length)
            {
                
                if (event.currentTarget == this["btn" + _loc_2])
                {
                    this.showPage(_loc_2);
                    break;
                }
                _loc_2++;
            }
            return;
        }// end function

        private function showPage(param1:int) : void
        {
            var _loc_2:int = 0;
            _loc_2 = 0;
            while (_loc_2 < this._pages.length)
            {
                
                if (param1 == (_loc_2 + 1))
                {
                    this._pages[_loc_2].showplan();
                }
                else
                {
                    this._pages[_loc_2].closeplan();
                }
                _loc_2++;
            }
            this._index = param1;
            if (param1 == 1)
            {
                btnbox.visible = false;
            }
            else
            {
                btnbox.visible = true;
            }
            return;
        }// end function

        public function update() : void
        {
            this._pages[(this._index - 1)].update();
            return;
        }// end function

        private function close() : void
        {
            this._instance.close();
            return;
        }// end function

        protected function completeHandler(event:Event) : void
        {
            var _loc_2:Object = null;
            var _loc_3:Object = null;
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            if (this.loader.data)
            {
                _loc_2 = JSONCode.decode(this.loader.data);
                if (_loc_2.errno == 0)
                {
                    ModelProxy.change("data", "vplan", _loc_2.data);
                }
                _loc_3 = ModelProxy.getValue("data", "vplan");
                if (_loc_3)
                {
                    _loc_4 = _loc_3.expire_time.month;
                    if (_loc_4 > 0)
                    {
                        yueimg.url = "cs2_vplan/xufeiy.png";
                    }
                    else
                    {
                        yueimg.url = "cs2_vplan/kaitongy.png";
                    }
                    _loc_5 = _loc_3.expire_time.year;
                    if (_loc_5 > 0)
                    {
                        nianimg.url = "cs2_vplan/xufein.png";
                    }
                    else
                    {
                        nianimg.url = "cs2_vplan/kaitongn.png";
                    }
                }
            }
            return;
        }// end function

        public function openRefresh() : void
        {
            var _loc_1:* = Config.gameParams.username;
            var _loc_2:* = new URLRequest("api/serverapi.php?request=vjihua&qid=" + _loc_1);
            this.loader = new URLLoader(_loc_2);
            this.loader.addEventListener(Event.COMPLETE, this.completeHandler);
            return;
        }// end function

    }
}
